//
//  KZNaviViewController.m
//  DuoChong
//
//  Created by 唐开江 on 14/11/24.
//  Copyright (c) 2014年 KangZhi. All rights reserved.
//

#import "KZNaviVC.h"

@interface KZNaviVC ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>

@end

@implementation KZNaviVC

- (void)viewDidLoad {
    [super viewDidLoad];

    [[UINavigationBar appearance] setBarTintColor: KZColor(20, 156, 255)];
    self.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar1.png"] forBarMetrics:UIBarMetricsDefault];

//    [[UINavigationBar appearance] setBackgroundColor:KZColor(20, 156, 255)];
    [[UINavigationBar appearance] setTintColor: [UIColor whiteColor]];

    
    UINavigationBar *appearance = [UINavigationBar appearance];
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [appearance setTitleTextAttributes:textAttrs];
    self.delegate = self;
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = self;
    }
    [UIBarButtonItem appearance];

}

//拦截push
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
   
    

        if (self.childViewControllers.count>0) {
            viewController.hidesBottomBarWhenPushed = YES;
            viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
            
            //右滑手势
            if (![self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//                self.interactivePopGestureRecognizer.delegate = nil;
                // fix 'nested pop animation can result in corrupted navigation bar'

                //修复pop动画导致的navigation bar 的闪退
                self.interactivePopGestureRecognizer.enabled = YES;

            }

        }
    
        [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

//返回
- (void)goBack
{
    
    [self popViewControllerAnimated:YES];

    
}

@end
